﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCFMINERP.MODEL;
using WCFMINERP.DAL;
using WCFMINERP.COM;


namespace WCFMINERP.BLL.Analyse
{
    /// <summary>
    /// 显示和处理分析时错误的订单
    /// </summary>
   public  class AnalysPres
    {
       /// <summary>
       /// 获取所有出错的记录
       /// </summary>
       /// <returns></returns>
       public List<UploadQueue_Info> GetAllErrList()
       {
           int ErrStatus = (int)TransferStatus.Error;
           List<UploadQueue_Info> list = new List<UploadQueue_Info>();
           using (newSampleYPDBEntities db = new newSampleYPDBEntities())
           {
               List<UploadQueue> listuq = db.UploadQueue.Where(p=>p.Status==ErrStatus).ToList();
               foreach (UploadQueue uq in listuq)
               {
                   UploadQueue_Info info = new UploadQueue_Info();
                   info.CreateTime = uq.CompleteTime;
                   info.FileLength = uq.FileLength;
                   info.Remark = uq.Remark;
                   info.ShopName = uq.ShopName;
                   info.ZipName = uq.ZipName;
                   info.UploadId = uq.UploadId;
                   list.Add(info);
               }
 
           }
           return list;
       }

       public  string GetPickUpOrderForder()
       {
           using (newSampleYPDBEntities db = new newSampleYPDBEntities())
           {
               return db.FileDirPath.FirstOrDefault(pt => pt.Des == "自动开单目录").FileDir;

           }
       }
       /// <summary>
       /// 转去手动开单
       /// </summary>
       /// <param name="inUQid"></param>
       public void SetCompleteById(int inUQid)
       {
           using (newSampleYPDBEntities db = new newSampleYPDBEntities())
           {
               UploadQueue uq = db.UploadQueue.FirstOrDefault(p=>p.UploadId==inUQid);
               uq.Status = (int)TransferStatus.AnlyseComplete;
               uq.Remark += "已经转去手动开单";
               db.SaveChanges();
 
           }
       }

       
       /// <summary>
       /// 修改网单的状态
       /// </summary>
       /// <param name="inOrderid">网单号</param>
       /// <param name="inStatus">状态</param>
       /// <returns>0正常1订单不存在-1出错</returns>
       public int SetOrderStatus(int inOrderid, int inStatus)
       {
           
           int rtnVal = 0;
           try
           {
               using (newSampleYPDBEntities db = new newSampleYPDBEntities())
               {
                   UploadQueue uq = db.UploadQueue.FirstOrDefault(p => p.UploadId == inOrderid);
                   if (uq != null)
                   {
                       uq.Status = inStatus;
                       rtnVal = 0;
                   }
                   else
                   {
                       rtnVal = 1;
                   }
                   db.SaveChanges();
               }
           }
           catch (Exception ex)
           {
               rtnVal= - 1;
           }
           return rtnVal;
       }
    }
}
